{extend name='template/base'}{/extend}
{extend name='template/base'}{/extend}
{block name='style'}
<link href="__STATIC__/plugins/jquery-treegrid/css/jquery.treegrid.css" rel="stylesheet" type="text/css"/>
<style>
    table {
        border: 1px solid #e4e4e4;
    }


    th, td {
        border-top: 1px solid #e4e4e4 !important;
        border-left: 1px solid #e4e4e4 !important;
    }

    #toolbar .btn-group {
        margin: 10px;
    }
</style>
{/block}
{block name='script'}
<script src="__STATIC__/plugins/bootstrap-treeview/bootstrap-treeview.min.js"></script>
{/block}
{block name='content'}
<section class="content">
    <!--表格开始--------------------------------------------------------------------------------------------------------------------------------->
    <div class="row">
        <div class="col-xs-12">
            <div id="toolbar">
                <div class="btn-group pull-left">
                    <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 自动生成菜单</a>
                </div>
                <div class="btn-group pull-right">
                    <a class="btn btn-default" onclick="window.location.reload()"><i class="fa fa-refresh"></i></a>
                </div>
            </div>
            <table class="table tree">
                <tr>
                    <th>菜单名称</th>
                    <th>模块</th>
                    <th>控制器</th>
                    <th>方法</th>
                    <th>操作</th>
                </tr>
                {foreach $list as $menu}
                <tr class="treegrid-{$menu.id}{if $menu.p_id>0} treegrid-parent-{$menu.p_id}{/if} ks-form"
                    id="tr{$menu.id}">
                    <td class="form-inline">
                        <!--<input class="form-control" type="text" name="name" value="{$menu.name}"/>-->
                        <span class="font-grey-cascade">{$menu.name}</span>
                        <!--<a href="{:url('category/category_add',['p_id'=>$menu.id])}"-->
                           <!--class="icon-plus hidden-xs tooltips" data-container="body" data-placement="right"-->
                           <!--data-html="true" data-original-title="增加子菜单"></a>-->
                    </td>
                    <td class="hidden-xs">
                        <span class="font-grey-cascade">{$menu.module}</span>
                    </td>
                    <td class="hidden-xs">
                        <span class="font-grey-cascade">{$menu.controller}</span>
                    </td>
                    <td class="hidden-xs">
                        <span class="font-grey-cascade">{$menu.function}</span>
                    </td>
                    <td>
                        <button onclick="edit_name('{$menu.id}')" class="btn btn-warning btn-xs row_role" href="javascript:void(0)">
                            <i class="fa fa-edit"></i> 修改菜单名称
                        </button>
                        <input class="form-control" type="hidden" name="id" value="{$menu.id}"/>
                    </td>
                </tr>
                {/foreach}
            </table>
        </div>
    </div>
</section>
{/block}
{block name='script_extra'}
<!--树形表格-------------------------------------------------------开始-->
<script src="__STATIC__/plugins/jquery-treegrid/js/jquery.treegrid.js" type="text/javascript"></script>
<script src="__STATIC__/plugins/jquery-treegrid/js/jquery.treegrid.bootstrap3.js" type="text/javascript"></script>
<script>
    var edit_data_url="{:url('AdminPower/edit')}";
    var import_power_url="{:url('System/create_menu')}";
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.tree').treegrid({
            expanderExpandedClass: 'fa fa-minus-square',
            expanderCollapsedClass: 'fa fa-plus-square'
        });
    });
    function urlFormat(url) {
        if( url.indexOf('.html')){
            url=url.replace('.html','')
        }
        return url;
    }

    function edit_name(id) {
        layer_open('修改菜单名称',urlFormat(edit_data_url)+'/id/'+id);
    }

    $('#add_btn').on('click',function () {
        $.ajax({
            url:import_power_url,
            success:function (res) {
                if(res.success){
                    layer.msg(res.message);
                    window.location.reload();
                }
            }
        })
    })
</script>
<!--树形表格-------------------------------------------------------结束-->
{/block}